package com.ajie.config;

import com.ajie.service.MiniHttpService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpExchangeAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

/**
 * @author: ajie
 * @createTime: 2024-08-17 14:27
 */
@Configuration
public class HttpInterfaceConfig {

    @Bean
    public WebClient webClient() {
        return WebClient.builder().build();
    }

    @Bean
    public MiniHttpService miniHttpService(WebClient client) {
        // 获得请求代理工厂
        HttpServiceProxyFactory build = HttpServiceProxyFactory.builder().exchangeAdapter(WebClientAdapter.create(client)).build();
        // 构建http声明式请求
        return build.createClient(MiniHttpService.class);
    }
}
